package com.zyf.service.img;

import cn.hutool.core.io.FileUtil;
import com.zyf.service.audio.HandleAudioService;
import com.zyf.service.video.VedioUtils;
import com.zyf.utils.FFmpegUtils;
import com.zyf.utils.ImageUtils;
import org.bytedeco.javacv.FFmpegFrameGrabber;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 处理图片合成操作类
 */
public class HandleImageHDService {
    /**
     * 批量将图片高清化
     */
    public String converImgTo4K(String videoPath) throws Exception {
        List<File> files = FileUtil.loopFiles(videoPath, file -> file.isFile() && (file.getName().contains(".jpg")));

        String newvideoFolder = videoPath+"_new";
        File file = new File(newvideoFolder);
        if (!file.exists()) {
            file.mkdir();
        }
        for(File imgfile:files){
            try {
                List<String> commands = new ArrayList<>();
                commands.add("E:\\project\\Real-ESRGAN-master\\Real-ESRGAN-window\\realesrgan-ncnn-vulkan.exe");
                commands.add("-i");
                commands.add(imgfile.getAbsolutePath());
                commands.add("-o");
                commands.add(newvideoFolder+File.separator+imgfile.getName());
                commands.add("-n");
                commands.add("realesrgan-x4plus-anime");

                String res= FFmpegUtils.execFFmpegCommand(commands);
                System.out.println(res);
            } catch (Exception e) {
                throw new RuntimeException("ffmpeg执行异常" + e.getMessage());
            }


        }
        return newvideoFolder;
    }


















}
